package com.lut.edu.apm.webCenter.config;

import com.lut.edu.apm.webCenter.expection.UnAuthorizationException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

/**
 * 自定义无权访问处理类
 *
 * @author Zhao Suzhen
 * @date `2024/6/4`
 */

@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    @SneakyThrows(UnAuthorizationException.class)
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) {
        //这里是想直接抛出一个无权访问的异常然后全局捕捉
        throw new UnAuthorizationException();

    }
}
